/**
 *
 */
package com.wedroid.r2d2.contact.handler;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wedroid.r2d2.contact.Contact;

/**
 * @author lute
 */
@Component
public class CompositeContactHandler implements ContactHandler, GroupMemberHandler {

    protected final Logger logger = LoggerFactory.getLogger(CompositeContactHandler.class);

    @Autowired
    private List<ContactHandler> contactHandlers;

    @Autowired
    private List<GroupMemberHandler> memberHandlers;

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.contact.handler.ContactHandler#handleContacts(java.lang.String, java.util.List)
     */
    public void handleContacts(String droidName, List<Contact> contacts) {
        for (ContactHandler handler : contactHandlers) {
            handler.handleContacts(droidName, contacts);
        }
    }

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.contact.handler.GroupMemberHandler#handleGroupMembers(java.lang.String, java.util.Map)
     */
    public void handleGroupMembers(String droidName, Map<Contact, List<Contact>> groupMembers) {
        for (GroupMemberHandler handler : memberHandlers) {
            try {
                handler.handleGroupMembers(droidName, groupMembers);
            } catch (Exception e) {
                logger.error("#handleGroupMembers - Handling group members of for droid [{}] encounters exception: {}", droidName, e);
            }
        }
    }

}
